package server;

import Constans.Constants;
import bean.Cons_Today;
import com.alibaba.fastjson.JSONObject;
import request.HttpUtil;

import java.net.URLEncoder;

/**
 * @author:zhengyilong
 * @email:1797344574@qq.com
 * @phone:13479394730
 * @desc:
 * @DateTime:2021/12/21 19:22
 **/
public class Cons {

    public static Cons_Today getCons(String consName){
        //对请求参数进行url编码
        String encode = URLEncoder.encode(consName);
        //请求示例：http://web.juhe.cn/constellation/getAll?consName=%E7%8B%AE%E5%AD%90%E5%BA%A7&type=today&key=申请的KEY
        String str = Constants.CONS_URL + "?consName=" + encode + "&type=" + "today" + "&key=" + Constants.CONS_KEY;
        //调用自定义get请求发送请求，并获取到响应回来的数据
        String result = HttpUtil.get(str);

        //将响应回来的json数据解析成对象类型
        return JSONObject.parseObject(result, Cons_Today.class);
    }

}

